iT邦幫忙

3

JavaScript偵測滑鼠滾輪(IE/FF/Opera/Safari)

  • 分享至 

  • xImage
  •  

想了解如何取得滑鼠滾輪事件並相容不同瀏覽器可以參考

function MouseWheel (e) {
  e = e || window.event;
  alert(['scrolled ', (( e.wheelDelta <= 0 || e.detail > 0) ? 'down' : 'up')].join(''));
}

// hook event listener on window object
if ('onmousewheel' in window) {
  window.onmousewheel = MouseWheel;
} else if ('onmousewheel' in document) {
  document.onmousewheel = MouseWheel;
} else if ('addEventListener' in window) {
  window.addEventListener("mousewheel", MouseWheel, false);
  window.addEventListener("DOMMouseScroll", MouseWheel, false);
}
​

Demo: http://jsfiddle.net/pKLVf/


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言